package com.wtao.testcamera;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.EditText;
import android.widget.VideoView;

import java.io.IOException;

/**
 * VideoView可以播放普通rtsp流数据，无法播放rtsp摄像头流的数据
 */
public class RtspActivity extends AppCompatActivity  {
    String TAG = "RtspActivity";
    private VideoView mVideoView;
    private EditText etUrl;
    private Boolean flag = true;
    String url = null;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rtsp);
        mVideoView = findViewById(R.id.videoView);
        etUrl = findViewById(R.id.etUrl);

        findViewById(R.id.btnPlay).setOnClickListener(v->{
            Log.e(TAG, "点击了");
            if(etUrl.getText()!=null){
                url = etUrl.getText().toString();
                setOnlineAd();
            }
        });

    }

    private void setOnlineAd(){
        if (url.startsWith("rtsp://")) {
            Log.e(TAG, "setOnlineAd()");
            //url是你要播放的视频
            mVideoView.setVideoURI(Uri.parse(url));

            mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    Log.e(TAG, "onPrepared");
                }
            });
            mVideoView.requestFocus();
            mVideoView.start();
        }
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();


    }
}